
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @search-reset="searchReset"
        @refresh-change="refreshChange"
        @selection-change="selectionChange"
        :cell-style="cellStyle"
      >
        <template slot="menuRight">
          <el-button
            size="small"
            @click="exportClick"
          >导出</el-button>
        </template>>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { fetchList,  dataExport } from '@/api/rca/swckitvmsubaccountdatareview'
import { tableOption, startDate, endDate } from '@/const/crud/rca/swckitvmsubaccountdatareview'
import { mapGetters } from 'vuex'
import { dateFormat } from '@/util/date';
import { handleExcelResponse, getQueryString } from "@/util/util";

export default {
  name: 'swckitvmsubaccountdatareview',
  data () {
    return {
      searchForm: {
        tradeDate: [startDate, endDate]
      },
      //searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption:tableOption,
      selection: [],
      dialogVisible: false,
      autoCleanForm: {},
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList () {
      return {
      };
    },
  },
  methods: {
    cellStyle({ row, column, rowIndex,columnIndex }) {
      if(6==columnIndex){
         if (row.alipayDifferenceA != 0) {
          return {
            color: "red",
          };
        } 
      }
      if(7==columnIndex){
         if (row.weChatDifferenceA != 0) {
          return {
            color: "red",
          };
        } 
      }
      if(8==columnIndex){
         if (row.diffSumA != 0) {
          return {
            color: "red",
          };
        } 
      }
      if(13==columnIndex){
         if (row.alipayDifferenceB != 0) {
          return {
            color: "red",
          };
        } 
      }
      if(14==columnIndex){
         if (row.weChatDifferenceB != 0) {
          return {
            color: "red",
          };
        } 
      }
      if(15==columnIndex){
         if (row.diffSumB != 0) {
          return {
            color: "red",
          };
        } 
      }

      /* //只给时间标红
      if(1==columnIndex){
        if (row.diffSumA != 0) {
          return {
            color: "red",
          };
        }
        if (row.diffSumB != 0) {
          return {
            color: "red",
          };
        }
      }*/
      
    },
    selectionChange (list) {
      this.selection = list.map(l => l.id);
    },
    async getList (page, params) {
      this.tableLoading = true
      const [startDate, endDate] = this.searchForm.tradeDate || [];
      try {
        const response = await fetchList(Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm,
          { startDate, endDate }
        ))

        this.tableData = response.data.data
        //this.page.total = response.data.data.total
        this.tableLoading = false
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
      } catch (e) {
        this.tableLoading = false
      }
    },
    async exportClick (row) {
      this.dataExport();
    },
    async dataExport () {
      const [startDate, endDate] = this.searchForm.tradeDate || [];
      if (!startDate || !endDate) {
        this.$message.error("日期范围不能为空");
        return;
      }
      let loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      })
      try {
        const res = await dataExport(Object.assign({}, this.searchForm, { startDate, endDate }));
        handleExcelResponse(res);
      } finally {
        loading.close();
      }
    },
    async searchChange (form, done) {
      this.searchForm = { ...form };
      const [startDate, endDate] = this.searchForm.tradeDate || [];
      if (!startDate || !endDate) {
        this.$message.error("日期范围不能为空");
        done();
        return;
      }
      try {
        await this.getList(this.page, this.searchForm);
      } finally {
        done();
      }
    },
    refreshChange () {
      this.getList(this.page)
    },
    searchReset () {

      this.page.currentPage = 1
      this.getList(this.page);
    },
  }
}
</script>
